import { AutoGuideStepBase } from "./AutoGuideStepBase";
import { IAutoGuideSteper } from "./IAutoGuideSteper";
import { AutoGuideData } from "../AutoGuideData";
import { Window } from "../../../../../component/window/Window";
import { DisplayUtil } from "../../../../../common/DisplayUtil";
import { LayerManager } from "../../../../manager/LayerManager";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { AutoGuideClickType } from "../AutoGuideClickType";
import { EffectManager } from "../../../../manager/EffectManager";
import { GuideArrowManager } from "../../../../manager/GuideArrowManager";
//class AutoGuideWinRectSteper
    
    export  class AutoGuideWinRectSteper extends AutoGuideStepBase implements IAutoGuideSteper
    {
        constructor()
        {
            super();
            return;
        }

        public guide(arg1: AutoGuideData, arg2: Window=null): void
        {
            if (arg1 == null) 
            {
                return;
            }
            if (arg2 == null) 
            {
                arg2 = DisplayUtil.getChildByPropety(LayerManager.windowLayer, "winTitleName", arg1.guideTypeValue) as Window;
            }
            if (arg2 == null) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideDelDoingRecord, arg1));
                return;
            }
            this._winContentContainer = arg2.contentContainer;
            _data = arg1;
            var loc1=new Object /* flash.geom.Rectangle */();
            var loc2=String(arg1.clickChildName).split(";");
            loc1.x = int(loc2[0]);
            loc1.y = int(loc2[1]);
            loc1.width = int(loc2[2]);
            loc1.height = int(loc2[3]);
            if (arg1.needMask) 
            {
                this.showMaskX(arg2.highestContentContainer, loc1);
            }
            if (arg1.needArrow) 
            {
                this.showArrowX(arg2.highestContentContainer, arg1, loc1);
            }
            if (arg1.needLineBox) 
            {
                this.showLineBoxX(arg2.highestContentContainer, loc1);
            }
            _datas[arg2.contentContainer] = arg1;
            if (arg1.clickType != AutoGuideClickType.Click) 
            {
                this._winContentContainer.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.clickWinChildHandler);
            }
            else 
            {
                this._winContentContainer.addEventListener(flash.events.MouseEvent.CLICK, this.clickWinChildHandler);
            }
            return;
        }

        protected showMaskX(arg1: Object /* flash.display.DisplayObjectContainer */, arg2: Object /* flash.geom.Rectangle */): void
        {
            DisplayUtil.drawHollowMask(mask, arg2.width, arg2.height);
            mask.x = arg2.x;
            mask.y = arg2.y;
            arg1.addChild(mask);
            return;
        }

        protected showLineBoxX(arg1: Object /* flash.display.DisplayObjectContainer */, arg2: Object /* flash.geom.Rectangle */): void
        {
            _lineBox = EffectManager.getLineBox(arg2.width + 4, arg2.height + 4);
            _lineBox.x = arg2.x - 2;
            _lineBox.y = arg2.y - 2;
            arg1.addChild(_lineBox);
            return;
        }

        protected showArrowX(arg1: Object /* flash.display.DisplayObjectContainer */, arg2: AutoGuideData, arg3: Object /* flash.geom.Rectangle */): void
        {
            flash.utils.clearTimeout(_arrowTimerId);
            arrow.updateDir(arg2.arrowDirection);
            var loc1=arg2.arrowDirection;
            switch (loc1) 
            {
                case GuideArrowManager.Dir_B:
                {
                    arrow.x = arg3.x + arg3.width / 2;
                    arrow.y = arg3.y - 9;
                    break;
                }
                case GuideArrowManager.Dir_L:
                {
                    arrow.x = arg3.x + arg3.width + 4;
                    arrow.y = arg3.y + arg3.height / 2;
                    break;
                }
                case GuideArrowManager.Dir_R:
                {
                    arrow.x = arg3.x - 4;
                    arrow.y = arg3.y + arg3.height / 2;
                    break;
                }
                case GuideArrowManager.Dir_T:
                {
                    arrow.x = arg3.x + arg3.width / 2;
                    arrow.y = arg3.y + arg3.height + 9;
                    break;
                }
            }
            arg1.addChild(arrow);
            return;
        }

        /* internal  */clickWinChildHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as Object /* flash.display.DisplayObject */;
            var loc2=_datas[loc1];
            loc1.removeEventListener(flash.events.MouseEvent.CLICK, this.clickWinChildHandler);
            loc1.removeEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.clickWinChildHandler);
            this._winContentContainer = null;
            DisplayUtil.removeMe(_mask);
            DisplayUtil.removeMe(_arrow);
            DisplayUtil.removeMe(_lineBox);
            EffectManager.disposeLineBox(_lineBox);
            if (loc2 != null) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideStepEnd, loc2));
                _datas[loc1] = null;
            }
            return;
        }

        public stop(arg1: AutoGuideData=null): void
        {
            if (this._winContentContainer != null) 
            {
                this._winContentContainer.removeEventListener(flash.events.MouseEvent.CLICK, this.clickWinChildHandler);
                this._winContentContainer.removeEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.clickWinChildHandler);
            }
            DisplayUtil.removeMe(_mask);
            DisplayUtil.removeMe(_arrow);
            DisplayUtil.removeMe(_lineBox);
            EffectManager.disposeLineBox(_lineBox);
            return;
        }

        /* internal */ /* var */_winContentContainer: Object /* flash.display.DisplayObject */;
    }
